/*
 * @(#)DomUtil.java $version 2010. 8. 11
 *
 * Copyright 2007-2010 NHN Corp. All rights Reserved. 
 * NHN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */
package com.nhncorp.usf.core.util;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

/**
 * 
 * @author Web Platform Development Team.
 *
 */
public class DomUtil {
	
	/**
	 * Gets the child by name.
	 * 
	 * @param parent the parent
	 * @param nodeName the node name
	 * 
	 * @return the child by name
	 */
	public static Node getChildByName(Node parent, String nodeName) {
		NodeList nodeList = parent.getChildNodes();
		Node item = null;
		
		for (int i = 0; i < nodeList.getLength(); i++) {
			item = nodeList.item(i);
			
			if (item.getNodeName().equals(nodeName)) {
				return item;
			}
		}
		
		return null;
	}

	/**
	 * Gets the child list by name.
	 * 
	 * @param parent the parent
	 * @param nodeName the node name
	 * 
	 * @return the child list by name
	 */
	public static List<Node> getChildListByName(Node parent, String nodeName) {
		List<Node> nodeList = new ArrayList<Node>();
		NodeList children = parent.getChildNodes();
		Node item = null;
		
		for (int i = 0; i < children.getLength(); i++) {
			item = children.item(i);
			
			if (item.getNodeName().equals(nodeName)) {
				nodeList.add(item);
			}
		}
		
		return nodeList;
	}
}
